package main;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

//объект класса текст создается при помощи метода createText из класса Reader
public class Text {
    private String name;
    private int numberOfSynonyms;
    private List<String> synonyms;
    private int numberOfStrings;
    private List<String> stringsOfText;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getNumberOfSynonyms() {
        return numberOfSynonyms;
    }

    public void setNumberOfSynonyms(int numberOfSynonyms) {
        this.numberOfSynonyms = numberOfSynonyms;
    }

    public List<String> getSynonyms() {
        return synonyms;
    }

    public void setSynonyms(List<String> synonyms) {
        this.synonyms = synonyms;
    }

    public int getNumberOfStrings() {
        return numberOfStrings;
    }

    public void setNumberOfStrings(int numberOfStrings) {
        this.numberOfStrings = numberOfStrings;
    }

    public List<String> getStringsOfText() {
        return stringsOfText;
    }

    public void setStringsOfText(List<String> stringsOfText) {
        this.stringsOfText = stringsOfText;
    }

    @Override
    public String toString() {
        return "Text{" +
                "name='" + name + '\'' +
                ", numberOfSynonyms=" + numberOfSynonyms +
                ", synonyms=" + synonyms +
                ", numberOfStrings=" + numberOfStrings +
                ", stringsOfText=" + stringsOfText +
                '}';
    }

    public List<List<String>> getWords() {
        List<List<String>> allWords = new ArrayList<List<String>>();
        Pattern p = Pattern.compile("\\w+|\\W+");
        for(int i = 0; i < stringsOfText.size(); i++) {
            Matcher m = p.matcher(stringsOfText.get(i));
            List<String> words = new ArrayList<String>();
            while (m.find()) {
                words.add(m.group());
            }
            allWords.add(words);
        }
        return allWords;
    }
}
